package sk.tramtatiri.data.dao.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import javax.persistence.TypedQuery;

import org.springframework.orm.jpa.JpaCallback;
import org.springframework.transaction.annotation.Transactional;

import sk.tramtatiri.data.dao.interfaces.UserDietDao;
import sk.tramtatiri.data.dao.interfaces.UserFoodDao;
import sk.tramtatiri.data.dataobjects.UserDiet;
import sk.tramtatiri.data.dataobjects.UserFood;

public class UserDietDaoJPAImp extends AbstractDaoJPAImpl<UserDiet> implements
UserDietDao {

	public UserDietDaoJPAImp() {
		super(UserDiet.class);
	}

	public List<UserDiet> findAll() {
		return getJpaTemplate().execute(new JpaCallback<List<UserDiet>>() {
			public List<UserDiet> doInJpa(EntityManager em)
					throws PersistenceException {
				TypedQuery<UserDiet> query = em.createQuery(
						"select ud from UserDiet ud", UserDiet.class);
				return query.getResultList();
			}
		});
	}

	public int countAll() {
		// TODO Auto-generated method stub
		return 0;
	}

	public UserDiet findName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

	@Transactional
	public void delete(UserDiet o) {
		UserDiet ud = getJpaTemplate().find(UserDiet.class,o.getId());
		getJpaTemplate().remove(ud);
	}


	

}
